Skip to content

Comments

Don't convert to Float64 in Printf#180

Closed
jmkuhn wants to merge 1 commit intoJuliaMath:masterfrom
jmkuhn:bigprint
Closed

Don't convert to Float64 in Printf#180
jmkuhn wants to merge 1 commit intoJuliaMath:masterfrom
jmkuhn:bigprint

Conversation

@jmkuhn
Copy link
Collaborator

@jmkuhn jmkuhn commented Feb 22, 2024

Fixes #178

Base.widen(::Type{Dec32}) = Dec64
Base.widen(::Type{Dec64}) = Dec128

Printf.tofloat(x::DecimalFloatingPoint) = BigFloat(x)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we need to pass a precision? Otherwise the BigFloat constructor may use too low a precision.

Why do we need a conversion at all here? Wouldn't it be possible to have Printf.tofloat(x::DecimalFloatingPoint) = x and support printing natively on decimal floating point values? It seems like a shame to do a lossy conversion to binary floating point for printing — kinda defeats the point.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also prefer to not go through BigFloat. In the original Printf PR, there is another interface mentioned where we could pass a buffer of digit chars and the location of the decimal point and have that formatted.
I would like to try that interface but I can't find it in the current code. JuliaLang/julia#32859 (comment) Is that interface implemented @quinnj ?

@jmkuhn jmkuhn closed this Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

printf is converting to Float64

2 participants